library(tidyverse)
## ── Attaching packages ───────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1 ✓ purrr 0.3.3
## ✓ tibble 2.1.3 ✓ dplyr 0.8.4
## ✓ tidyr 1.0.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.4.0
## ── Conflicts ──────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
###exercise 1
SNPs<- read.table("23andMe_complete.txt", header = TRUE, sep = "\t")
p<-ggplot(SNPs,aes(chromosome))+
geom_bar(fill = "blue") +
ggtitle("Total SNPs for each genotype")+
ylab("SNP count") +
xlab("chromosome")
p
#exercise 2
mycolor<-c("AA"="blue", "AC"="blue", "AG"="blue", "AT"="blue", "CC"="blue", "CG"="blue", "CT"="blue", "GG"="blue", "GT"="blue", "TT"="blue","A"="pink", "C"="pink", "G"="pink", "T"="pink", "D"="orange", "DD"="orange", "DI"="orange","I"="orange","II"="orange","--"="green")
ggplot(SNPs, aes(chromosome, fill = genotype))+
geom_bar(color = "black")+
ggtitle("Total SNPs count for each chromosome")+
ylab("SNP count")+
xlab("chromosome ")+
scale_fill_manual(values=c(mycolor))
#exercise 3
ppi <- 300
png("Lab3_Exercise5_plot.png", width=6*ppi, height=6*ppi, res=ppi)
ggplot(data=SNPs, aes(chromosome, fill = genotype))+
geom_bar(position = "dodge")
dev.off()
## quartz_off_screen
## 2
#exercise 4
SNPs$chromosome=ordered(SNPs$chromosome, levels=c(seq(1,22),"X","Y","MT"))
ggplot(SNPs, aes(chromosome, fill = genotype))+
geom_bar(position = "dodge")+
facet_wrap(~genotype, ncol = 2)+
ggtitle("Genotype for Each Type of Chromosome")+
ylab("Genotype Count (Thousands)")+
xlab("Type of Chromosome")
#exercise 5
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
SNPs$chromosome=ordered(SNPs$chromosome,levels=c(seq(1,22),"X","Y","MT"))
p <- ggplot(SNPs, aes(chromosome, fill = genotype))+
geom_bar(position = "dodge")+
facet_wrap(~genotype, ncol = 2)
p <- ggplotly(p)
p
#exercise 6
library(DT)
chromosome_subset<-subset(SNPs, chromosome=="Y")
datatable(chromosome_subset)
## Warning in instance$preRenderHook(instance): It seems your data is too big
## for client-side DataTables. You may consider server-side processing: https://
## rstudio.github.io/DT/server.html